//
//  BiSaleApplyManageViewController.m
//  TrunkIndustryManageSystem
//
//  Created by 李璐西 on 15-4-22.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiSaleApplyManageViewController.h"

@interface BiSaleApplyManageViewController ()<UITextViewDelegate>{
    
    __weak IBOutlet UIScrollView *_ScrollView;
}
@property (weak, nonatomic) IBOutlet UILabel *labAppler;
@property (weak, nonatomic) IBOutlet UILabel *labcarType;
@property (weak, nonatomic) IBOutlet UILabel *labStarttime;
@property (weak, nonatomic) IBOutlet UILabel *labReturnTime;
@property (weak, nonatomic) IBOutlet UILabel *labDes;
@property (weak, nonatomic) IBOutlet UILabel *labCarNum;
@property (weak, nonatomic) IBOutlet UILabel *labCost;
@property (weak, nonatomic) IBOutlet UILabel *labDistance;
@property (weak, nonatomic) IBOutlet UILabel *labJoiner;
@property (weak, nonatomic) IBOutlet UITextView *textVRemark;
@property (weak, nonatomic) IBOutlet UITextView *textVReason;

@end

@implementation BiSaleApplyManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    
//    [self setNavBackBtn];
//    
//    [self setNavBarTitle:@"申请行销"];
//    
//    [self setNavBarWithHidden:NO];
//    
//    [self addTestView];
    [self setNavBackBtn];
    [self setNavBarTitle:@"申请行销申请批准(主管)"];
    [self setNavBarWithHidden:NO];
    [self addTestView];
    
    self.textVRemark.layer.borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:100.0].CGColor;
    self.textVRemark.layer.borderWidth = 0.5;
    
    self.textVReason.layer.borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:100.0].CGColor;
    self.textVReason.layer.borderWidth = 0.5;
    
    _ScrollView.contentSize = CGSizeMake(320, 600);
    
    self.labAppler.text = [BiUserEntity sharedInstance].name;
    
    _ScrollView.contentSize = CGSizeMake(MAIN_SCREEN_WIDTH, 504);

    [self dataFill];
}

- (void)dataFill{
    if(self.Centity){
        _labAppler.text = self.Centity.userApplyName;
        _labStarttime.text = self.Centity.gooffTime;
        _labReturnTime.text = self.Centity.returnTime;
        _labCarNum.text = self.Centity.licensePlate;
        _labJoiner.text = self.Centity.participant;
//        switch (self.Centity.useCarType.intValue) {
//            case 0:
//                _labcarType.text = @"无";
//                break;
//            case 1:
//                _labcarType.text = @"自有";
//            case 2:
//                _labcarType.text = @"公有";
//            default:
//                break;
//        }
        if(self.Centity.useCarType.hash == @"0".hash)
        {
            _labcarType.text = @"无";
        }
        else if (self.Centity.useCarType.hash == @"1".hash)
        {
            _labcarType.text = @"自有";
        }
        else
        {
            _labcarType.text = @"公有";
        }
        _labDes.text = self.Centity.destination;
        _labCost.text = self.Centity.fee;
        _labDistance.text = self.Centity.kilometre;
        _textVRemark.text = self.Centity.remark;
        _textVReason.text = self.Centity.xingxiaoRejectReason;
    }
    
}

- (IBAction)btnPermissionClick:(UIButton *)sender{

            
    NSDictionary * paraDic = [NSDictionary dictionaryWithObjectsAndKeys:self.Centity.e_id,@"id",
                                                  [BiUserEntity sharedInstance].userid,@"xingxiaoApproverId",
                                                  [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm:ss"],@"xingxiaoApproveTime",
                                                  _textVReason.text,@"xingxiaoRejectReason",
                                                  [NSString stringWithFormat:@"%d",(int)sender.tag],@"status",nil];
    [[BiNetEngine shareInstance] requestSaleApplyCheck:self paraDict:paraDic];
                              
    [self asyshowHUDView:WAITING CurrentView:self];
    
}


#pragma mark -textview delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if ([@"\n" isEqualToString:text] == YES)
    {
        [textView resignFirstResponder];
        
        
        return NO;
    }
    return YES;
}


- (void)textViewDidBeginEditing:(UITextView *)textView{
    
    _ScrollView.frame = CGRectMake(0, _ScrollView.frame.origin.y - 190, MAIN_SCREEN_WIDTH, _ScrollView.frame.size.height);
}
- (void)textViewDidEndEditing:(UITextView *)textView{

    _ScrollView.frame = CGRectMake(0, _ScrollView.frame.origin.y + 190, MAIN_SCREEN_WIDTH, _ScrollView.frame.size.height);
}

#pragma -mark Net Delegate
- (void)onNetEngineResponse:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    
    [self removeHUDView:self];
    
    NSDictionary * entity_ = (NSDictionary *)entity;
    
    [self showMessage:entity_[@"result_info"]];
    
    if ([entity_[@"response_status"] integerValue] != 200) {
        
        return;
        
    }
    
    switch (tag) {
        case NET_GET_XINGXIAO_SALEAPPLY_CHECK:
        {
            [self.navigationController popViewControllerAnimated:YES];
            
        }
            break;

        default:
            break;
    }
    
    
    
}
- (void)onNetEngineResponseFail:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    [self removeHUDView:self];
    
}


@end
